<?php
declare (strict_types=1);

namespace app\dao\adv;

use app\dao\BaseDao;
use app\model\adv\Adv;
use think\db\exception\{DataNotFoundException, DbException, ModelNotFoundException};

/**
 *
 * Class AdvDao
 * @package app\dao\adv
 * @mixin Adv
 */
class AdvDao extends BaseDao
{

    /**
     * 设置模型
     * @return string
     */
    protected function setModel(): string
    {
        return Adv::class;
    }

    /**
     * @param array $where
     * @param array $field
     * @param int $page
     * @param int $limit
     * @return array
     * @throws DataNotFoundException
     * @throws DbException
     * @throws ModelNotFoundException
     */
    public function getList(array $where, array $field, int $page = 0, int $limit = 0): array
    {
        return $this->search($where)
            ->when($page && $limit, function ($query) use ($page, $limit) {
                $query->page($page, $limit);
            })->field($field)->order('id asc')->select()->toArray();
    }
}
